package cc.javaee.bbs.model.activity;

import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/*
 * 活动奖品表
 * 
 */
@Data
public class KbrActivityPrize {

    private Integer id;
    private Integer actId;
    private String name;
    private String prize;
    private Integer count;
    private Integer sort;
    private String describer;
    private Integer usedCount;

    public Integer remainingPrize() {
        return (count != null ? count : 0) - (usedCount != null ? usedCount : 0);
    }


    public List<KbrActivityPrize> batchClone(int count) {
        List result = new ArrayList();
        for (int i = 0; i < count; i++) {
            KbrActivityPrize prize = new KbrActivityPrize();
            BeanUtils.copyProperties(this, prize);
            result.add(prize);
        }
        return result;
    }

    public List<KbrActivityPrize> batchCloneAndThis() {
        List<KbrActivityPrize> prizes = batchClone(remainingPrize() - 1);
        prizes.add(this);
        return prizes;
    }
}
